import asyncio
from pathlib import Path
from autogen_ext.tools.mcp import StdioServerParams, mcp_server_tools
from autogen_agentchat.agents import AssistantAgent
from autogen_core import CancellationToken
from LLMClient.QwenClient import Qwen_model_client as model_client
from autogen_agentchat.ui import Console

async def main() -> None:
    # 设置服务器参数以访问本地文件系统
    desktop = str(Path.home() / "Desktop")
    server_params = StdioServerParams(
        command="npx.cmd", args=["-y", "@modelcontextprotocol/server-filesystem", r"D:\work\auto-gen-doc-learn"]
    )

    # 从服务器获取所有可用工具
    tools = await mcp_server_tools(server_params)

    # Create an agent that can use all the tools
    agent = AssistantAgent(
        name="file_manager",
        model_client=model_client,
        tools=tools,  # type: ignore
         model_client_stream=True,  # 流式加载.
    )

    # The agent can now use any of the filesystem tools
    
    await Console(agent.run_stream(task="Create a file called test.txt with some content", cancellation_token=CancellationToken()))

if __name__ == "__main__":
    asyncio.run(main())
